package com.jackrain.nea.fc.cp.mapper;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 供应商档案接口-服务开发
 * Mapper
 *
 * @author WSL
 * @create 2017/10/20
 */
@Mapper
public interface ViewCsupplierMapper {

    class SelectPro
    {
        public String selectProvider(Map map)
        {
            return new SQL()
            {
                {
                    SELECT("ECODE,ENAME,CP_C_SUPPGRADE_ID,CP_C_SUPPAREA_ID,STATE,ISSPLIT,ALLNAME,GROUPNAME,ADDRESS,CP_C_WAREHOUSE_ID,MOBIL," +
                            "CONTACTER,RELYRATE,PHONE,FAX,EMAIL,POST,BILLACCOUNT,REMARK,CREATIONDATE,RETDAYS,ISACTIVE,MODIFIERID,MODIFIEDDATE,BILLBANK," +
                            "CP_C_SUPPCATE_ID,CP_C_TITY_ID,DATEBEGIN,DATEEND");
                    FROM("CP_C_SUPPLIER");
                    Object[] list = (Object[]) map.get("list");
                    StringBuilder sb = new StringBuilder("(");
                    for (Object num : list) {
                        sb.append(num).append(",");
                    }
                    sb.deleteCharAt(sb.length()-1).append(")");
                    WHERE("ID IN "+sb.toString());
                }
            } .toString();
        }
    }

    /**
     * 根据param查询条件 查询【供应商档案】表
     * @param param
     * @return String
     */
    @SelectProvider(type = SelectPro.class, method = "selectProvider")
    List<HashMap> selectProvider(@Param("list") Object[] param);

    /**
     * 查询【供应商属性值】ECODE
     * @param id
     * @return String
     */
    @Select("SELECT ECODE FROM CP_C_SUPPDIM_ITEM WHERE ID = #{id}")
    String selSupdimItemEcode(Long id);

    /**
     * 查询【店仓档案】ECODE
     * @param id
     * @return String
     */
    @Select("SELECT ECODE FROM CP_C_STORE WHERE ID = #{id}")
    String selStoreEcode(Long id);

    /**
     * 查询【用户】ENAME
     * @param id
     * @return
     */
    @Select("SELECT ENAME FROM USERS WHERE ID = #{id}")
    String selUserEname(Long id);

    /**
     * 查询【城市】
     * @param id
     * @return
     */
    @Select("SELECT ECODE FROM CP_C_REGION WHERE ID = #{id}")
    String selRegionEcode(Long id);
}
